<%-- 
    Document   : ViewCart
    Created on : Sep 27, 2011, 1:51:50 PM
    Author     : James
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List, java.util.ArrayList, servlet.Cart, BusinessLogic.Constants, EntityState.ItemDetailsState, EntityState.ReservationState, EntityState.ItemState, EntityState.VoucherState, EntityState.ReservableUnitState, org.joda.time.DateTime, org.joda.time.DateTimeZone"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Lingua123 - Your shortcut to a new language</title>
        <link rel="stylesheet" href="../customer/main_style_sheet.css" />
        <script type="text/javascript" src="../customer/script/Utilities.js"></script>
        <script type='text/javascript' src='../jQuery/jquery-1.6.1.min.js'></script>
        <script type="text/javascript">
            <!--
            window.onload = showPage('Login', 'login_panel');
            //-->
        </script>
    </head>
    <body>
        <div id="wrapper">
            <h1>Lingua123</h1>
            <div id="nav">
                <a href="Redirect?page=CourseRegistration">Course Registration</a>
                <a href="Redirect?page=search&target=ad">About Us</a>
                <a href="Redirect?page=about_us">Our Languages</a>
                <a href="Redirect?page=contact">Support</a>
            </div>
            <div id="body">
                <div id="body-top">
                    <div id="body-bot">
                        <div id="welcome">
                            <img src="../customer/images/handshake.jpeg" width="276" height="238" alt="Pic 1" />
                        </div>
                        <div id="login_panel"></div>
                        <div id="content">
                            <%
                                // Get the cart or create a new one if the customer doesn't have one
                                session = request.getSession();
                                Cart cart = (Cart) session.getAttribute("cart");
                                if (cart == null) {
                                    cart = new Cart();
                                    session.setAttribute("cart", cart);    
                                } 
                            %>
                            <p style="color:purple;font-size:15px">Your reservations</p>
                            <hr><br/>    
                            <table>
                                <tr>
                                    <td>Outlet</td>
                                    <td>Unit name</td>
                                    <td>Start</td>
                                    <td>End</td>
                                    <td>No. of People</td>
                                    <td>Customer's name</td>
                                    <td>Contact no.</td>
                                    <td>Food vouchers</td>
                                    <td>No-show fee</td>
                                    <td></td>
                                    <td></td>
                                </tr>
                            <%
                                // Get list of Reservations
                                List<Cart.CartItem> listOfCartItems = cart.getListOfCartItems();
                                for (Cart.CartItem item : listOfCartItems) {
                                    if (item.theReservation != null) {
                                        ReservationState rs = item.theReservation;
                                        ReservableUnitState reservedUnit = rs.getReservedUnit();
                            %>
                                <tr>
                                    <td><%= reservedUnit.getOutlet().getName() %></td>
                                    <td><%= reservedUnit.getReservedItem().getName() %></td>
                                    <td><%= new DateTime(rs.getStartTime(), DateTimeZone.forID(reservedUnit.getOutlet().getTimezone())).toString("MMMM dd, yyyy HH:mm") %></td>
                                    <td><%= new DateTime(rs.getStartTime(), DateTimeZone.forID(reservedUnit.getOutlet().getTimezone())).toString("MMMM dd, yyyy HH:mm") %></td>
                                    <td><%= rs.getNumOfPeople() %></td>
                                    <td><%= rs.getCustomerName() %></td>
                                    <td><%= "(+" + rs.getCountryCode() + ") " + rs.getPhone() %></td>
                                    <td>
                                        <%
                                            for (VoucherState vs : rs.getListOfVouchers()) {
                                                System.out.println(vs.getId());
                                            }
                                        %>
                                    </td>
                                    <td><%= reservedUnit.getLatestReservableUnitDetails().getReservationNoShowFee() %></td>
                                    <td><button type="button">Update</button></td>
                                    <td><button type="button">Cancel</button></td>
                                </tr>
                            <%
                                    }
                                }
                            %>
                            </table>
                            <p style="color:purple;font-size:15px">Your items</p>
                            <hr><br/>    
                            <table>
                                <tr>
                                    <td>Name</td>
                                    <td>Price</td>
                                    <td>Discount</td>
                                    <td>Additional Loyalty points</td>
                                    <td>Quantity</td>
                                    <td></td>
                                    <td></td>
                                </tr>
                            <%
                                // Get list of Items
                                int i = 0;
                                for (Cart.CartItem item : listOfCartItems) {
                                    i++;
                                    if (item.theItem != null) {
                                        ItemState         is = item.theItem;
                                        ItemDetailsState ids = is.getLatestItemDetails();
                            %>
                                <tr>
                                    <td><%= is.getName() %></td>
                                    <td><%= "$" + ids.getPrice()/100 + "." + ids.getPrice()%100 %></td>
                                    <td>
                                        <%
                                            int discount = ids.getDiscount();
                                            if (discount < 0) discount = ids.getPrice()*(discount*-1)/100;
                                            System.out.print("$" + discount);
                                        %>
                                    </td>
                                    <td><%= ids.getAdditionalLoyaltyPoint() %></td>
                                    <td>
                                        <input type="hidden" value="<%= Constants.CART_UPDATE_ITEM_QUANTITY %>" name="<%= "action"+i %>" />
                                        <input type="hidden" value="<%= item.id %>" name="<%= "itemID"+i %>" />
                                        <input type="text" value="<%= item.quantity %>" name="<%= "quantity"+i %>" />
                                    </td>
                                    <td><button type="submit" value="Update" onclick="update(<%= i %>)">Update</button></td>
                                    <td>
                                        <input type="hidden" value="<%= Constants.CART_DELETE_CART_ITEM %>" name="<%= "action"+i %>" />
                                        <input type="hidden" value="<%= item.id %>" name="<%= "itemID"+i %>" />
                                    </td>
                                    <td><button type="submit" value="Drop" onclick="update(<%= i %>)">Drop/button></td>
                                </tr>
                            <%
                                    }
                                }
                            %>
                            </table>
                        </div>
                        <div class="clear"></div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>


